#!/bin/bash
pkg install dialog
# 定义函数来安装相应的软件包
install_lua51() {
  clear
  pkg install lua51
}

install_lua52() {
  clear
  pkg install lua52
}

install_lua53() {
  clear
  pkg install lua53
}

install_lua54() {
  clear
  pkg install lua54
}

install_java8() {
  clear
  pkg install openjdk-8
}

install_java11() {
  clear
  pkg install openjdk-11
}

install_java17() {
  clear
  pkg install openjdk-17
}

install_php74() {
  clear
  pkg install php74
}

install_php80() {
  clear
  pkg install php80
}

install_php81() {
  clear
  pkg install php81
}

install_nginx() {
  clear
  pkg install nginx
}

install_c() {
  clear
  pkg install clang
}

install_cpp() {
  clear
  pkg install clang
}

install_gcc() {
  clear
  pkg install gcc
}

install_Cpp2() {
  clear
  pkg install g++
}

install_python36() {
  clear
  pkg install python36
}

install_python38() {
  clear
  pkg install python38
}

install_python39() {
  clear
  pkg install python39
}

install_python310() {
  clear
  pkg install python310
}

# 显示主菜单
while true; do
  # 使用dialog创建菜单
  choice=$(dialog --stdout --title "选择要安装的环境" \
    --menu "请选择您想要安装的环境:" 20 80 10 \
    1 "Lua" \
    2 "Java" \
    3 "Nginx" \
    4 "PHP" \
    5 "C 编译器 (Clang)" \
    6 "C++ 编译器 (Clang)" \
    7 "C 编译器 (GCC)" \
    8 "C++ 编译器 (G++)" \
    9 "Python" \
    10 "退出")

  case $choice in
    1)
      # 显示Lua版本选择菜单
      lua_version=$(dialog --stdout --title "选择Lua版本" \
        --menu "请选择您想要安装的Lua版本:" 20 80 10 \
        1 "Lua 5.1" \
        2 "Lua 5.2" \
        3 "Lua 5.3" \
        4 "Lua 5.4")

      case $lua_version in
        1)
          install_lua51
          ;;
        2)
          install_lua52
          ;;
        3)
          install_lua53
          ;;
        4)
          install_lua54
          ;;
        *)
          dialog --msgbox "无效的选择，请重试。" 5 30
          ;;
      esac
      ;;

    2)
      # 显示Java版本选择菜单
      java_version=$(dialog --stdout --title "选择Java版本" \
        --menu "请选择您想要安装的Java版本:" 20 80 10 \
        1 "OpenJDK 8" \
        2 "OpenJDK 11" \
        3 "OpenJDK 17")

      case $java_version in
        1)
          install_java8
          ;;
        2)
          install_java11
          ;;
        3)
          install_java17
          ;;
        *)
          dialog --msgbox "无效的选择，请重试。" 5 30
          ;;
      esac
      ;;

    3)
      install_nginx
      ;;

    4)
      # 显示PHP版本选择菜单
      php_version=$(dialog --stdout --title "选择PHP版本" \
        --menu "请选择您想要安装的PHP版本:" 20 80 10 \
        1 "PHP 7.4" \
        2 "PHP 8.0" \
        3 "PHP 8.1")

      case $php_version in
        1)
          install_php74
          ;;
        2)
          install_php80
          ;;
        3)
          install_php81
          ;;
        *)
          dialog --msgbox "无效的选择，请重试。" 5 30
          ;;
      esac
      ;;

    5)
      install_c
      ;;

    6)
      install_cpp
      ;;

    7)
      install_gcc
      ;;

    8)
      install_Cpp2
      ;;

    9)
      # 显示Python版本选择菜单
      python_version=$(dialog --stdout --title "选择Python版本" \
        --menu "请选择您想要安装的Python版本:" 20 80 10 \
        1 "Python 3.6" \
        2 "Python 3.8" \
        3 "Python 3.9" \
        4 "Python 3.10")

      case $python_version in
        1)
          install_python36
          ;;
        2)
          install_python38
          ;;
        3)
          install_python39
          ;;
        4)
          install_python310
          ;;
        *)
          dialog --msgbox "无效的选择，请重试。" 5 30
          ;;
      esac
      ;;

    10)
      clear
      exit 0
      ;;

    *)
      dialog --msgbox "无效的选择，请重试。" 5 30
      ;;
  esac
done